#include "DhData.h"

#include <float.h>
#include <limits.h>

bool CDhData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CDhData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CDhData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CDhData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CDhData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CDhData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CDhData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CDhData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CDhData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CDhData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CDhData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CDhData::InitToInvalid()
{
    m_uCommState = 0xFFFF;
    for (int i = 0; i < 99; ++i)
    {
        m_uRev[i] = 0xFFFF;
    }

    for (int i = 0; i < 100; ++i)
    {
        m_fRev[i] = FLT_MAX;
    }

    //转发的100个UINT16数据
    m_uRunState = 0xFFFF;
    m_uFaultState = 0xFFFF;
    m_uAlarmState = 0xFFFF;
    m_uSwitchState = 0xFFFF;
    for (int i = 0; i < 96; ++i)
    {
        m_uData[i] = 0xFFFF;
    }

    //转发的100个FLOAT数据
    m_fInsideTemp = FLT_MAX;
    m_fInsideHumi = FLT_MAX;
    m_fOutsideTemp = FLT_MAX;
    m_fOutsideHumi = FLT_MAX;
    for (int i = 0; i < 96; ++i)
    {
        m_fData[i] = FLT_MAX;
    }

    m_fSetTempStart = FLT_MAX;
    m_fSetTempStartCopy = FLT_MAX;
    m_fSetTempStop = FLT_MAX;
    m_fSetTempStopCopy = FLT_MAX;
    m_fSetTempDiff = FLT_MAX;
    m_fSetTempDiffCopy = FLT_MAX;
    m_fSetHumiStart = FLT_MAX;
    m_fSetHumiStartCopy = FLT_MAX;
    m_fSetHumiStop = FLT_MAX;
    m_fSetHumiStopCopy = FLT_MAX;
    m_fSetHumiDiff = FLT_MAX;
    m_fSetHumiDiffCopy = FLT_MAX;

    for (int i = 0; i < 24; ++i)
    {
        m_uSetData[i] = 0xFFFF;
        m_uSetDataCopy[i] = 0xFFFF;
    }
}

void CDhData::InitToZero()
{
    m_uCommState = 0;
    for (int i = 0; i < 99; ++i)
    {
        m_uRev[i] = 0;
    }

    for (int i = 0; i < 100; ++i)
    {
        m_fRev[i] = 0.0;
    }

    //转发的100个UINT16数据
    m_uRunState = 0;
    m_uFaultState = 0;
    m_uAlarmState = 0;
    m_uSwitchState = 0;
    for (int i = 0; i < 96; ++i)
    {
        m_uData[i] = 0;
    }

    //转发的100个FLOAT数据
    m_fInsideTemp = 0.0;
    m_fInsideHumi = 0.0;
    m_fOutsideTemp = 0.0;
    m_fOutsideHumi = 0.0;
    for (int i = 0; i < 96; ++i)
    {
        m_fData[i] = 0.0;
    }

    m_fSetTempStart = 0.0;
    m_fSetTempStartCopy = 0.0;
    m_fSetTempStop = 0.0;
    m_fSetTempStopCopy = 0.0;
    m_fSetTempDiff = 0.0;
    m_fSetTempDiffCopy = 0.0;
    m_fSetHumiStart = 0.0;
    m_fSetHumiStartCopy = 0.0;
    m_fSetHumiStop = 0.0;
    m_fSetHumiStopCopy = 0.0;
    m_fSetHumiDiff = 0.0;
    m_fSetHumiDiffCopy = 0.0;

    for (int i = 0; i < 24; ++i)
    {
        m_uSetData[i] = 0;
        m_uSetDataCopy[i] = 0;
    }
}

void CDhData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < 99; ++i)
    {
        m_uRev[i] = uvalue;
    }

    for (int i = 0; i < 100; ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    for (int i = 0; i < 96; ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fInsideTemp = fvalue;
    m_fInsideHumi = fvalue;
    m_fOutsideTemp = fvalue;
    m_fOutsideHumi = fvalue;
    for (int i = 0; i < 96; ++i)
    {
        m_fData[i] = fvalue;
    }

    m_fSetTempStart = fvalue;
    m_fSetTempStartCopy = fvalue;
    m_fSetTempStop = fvalue;
    m_fSetTempStopCopy = fvalue;
    m_fSetTempDiff = fvalue;
    m_fSetTempDiffCopy = fvalue;
    m_fSetHumiStart = fvalue;
    m_fSetHumiStartCopy = fvalue;
    m_fSetHumiStop = fvalue;
    m_fSetHumiStopCopy = fvalue;
    m_fSetHumiDiff = fvalue;
    m_fSetHumiDiffCopy = fvalue;

    for (int i = 0; i < 24; ++i)
    {
        m_uSetData[i] = uvalue;
        m_uSetDataCopy[i] = uvalue;
    }
}
